package gui;

import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import client.Main;


public class GreetingGUI extends JFrame{
	
	JPanel panel;
	
	JComboBox cmbGreetOption;
	
	JLabel lblHeader;
	
	public JTextArea txtText;
	
	JButton btnSubmit;
	JButton btnBack;
	
	String[] greets={"Choose...","Birthday","Marrige","Bar Mitzva","GREAT SEX !!!"};
	String[] words={"",
					"Happy Birthday to you she ha'shanim ya'avru bekef be'simha u be'osher",
					"y did u this mistake ?!?!? fuck off",
					"u fucking idiot child, u r now only 13 ! u r not allowed to drink",
					"LOVE UR SEX, it was great"};
	
	public GreetingGUI()
	{
		super();
		init();
	}
	
	JComboBox getComboGreetOptions()
	{
		if(cmbGreetOption==null)
		{
			cmbGreetOption=new JComboBox();
			for(int i=0;i<greets.length;i++)
				cmbGreetOption.addItem(greets[i]);
			cmbGreetOption.setBounds(100, 50, 150, 20);
			cmbGreetOption.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()");
					txtText.setText(words[cmbGreetOption.getSelectedIndex()]);
				}
			});
		}
		return cmbGreetOption;
	}
	
	JButton getButtonBack()
	{
		if(btnBack==null)
		{
			btnBack=new JButton();
			btnBack.setText("Cancel");
			btnBack.setBounds(380, 10, 100, 40);
		}
		return btnBack;
	}
	
	JButton getButtonSubmit()
	{
		if(btnSubmit==null)
		{
			btnSubmit=new JButton();
			btnSubmit.setText("OK");
			btnSubmit.setBounds(200, 300, 100, 40);
		}
		return btnSubmit;
	}
	
	JTextArea getTextFieldText()
	{
		if(txtText==null)
		{
			txtText=new JTextArea();
			txtText.setBounds(100, 70, 300, 200);
			txtText.setLineWrap(true);
		}
		return txtText;
	}
	
	JLabel getLabelHeader()
	{
		if(lblHeader==null)
		{
			lblHeader=new JLabel();
			lblHeader.setText("Greeting Card");
			lblHeader.setBounds(this.getWidth()/2-300/2, 20, 300, 30);
			lblHeader.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblHeader;
	}
	
	JPanel getPanel()
	{
		if(panel==null)
		{
			panel=new JPanel();
			panel.setSize(this.getWidth(),this.getHeight());
			panel.setLayout(null);
			
			//labels
			panel.add(getLabelHeader());
			
			// textField
			panel.add(getTextFieldText());
			
			//combo
			panel.add(getComboGreetOptions());
			
			//button
			panel.add(getButtonSubmit());
			panel.add(getButtonBack());
			
		}
		return panel;
	}
	
	void init()
	{
		this.setBounds((int)Main.dim.getWidth()/2-260, (int)Main.dim.getHeight()/2-275, 500, 400);
		this.setLocation((int)Main.dim.getWidth()/2 - (int)this.getPreferredSize().getWidth()/2,(int)Main.dim.getHeight()/2 - (int)this.getPreferredSize().getHeight()/2);
		this.setTitle("Zer Lah - Delivery");
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		this.setResizable(false);
		this.add(getPanel());
		this.setVisible(true);
	}
}
